package com.lagou.client;

import com.lagou.service.UserService;
import com.lagou.service.com.lagou.util.RpcRequest;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;

public class ClientBootStrap {

//    public static  final String providerName="UserService#sayHello#";

    public static  RpcRequest request;

    static {
        RpcRequest request1 = new RpcRequest();
        request1.setMethodName("sayHello");
        request1.setClassName("userService");
        request1.setRequestId(UUID.randomUUID().toString());
        request = request1;
    }

    public static void main(String[] args)  {

        RpcConsumer rpcConsumer = new RpcConsumer();


//        UserService proxy = (UserService) rpcConsumer.createProxy(UserService.class, request, userClientHandler);
        //  从RpcConsumer中获取维护的服务list

        try {
            rpcConsumer.initClient();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        while (true){
            try {

                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


//            System.out.println("ssssss");
            LinkedHashMap<String, Long> map = (LinkedHashMap<String, Long>) rpcConsumer.getMap();
            Map.Entry<String, Long> head = ClientBootStrap.getHead(map);
            Map<String, UserService> stringUserServiceMap = rpcConsumer.getsMap();
            System.out.println(stringUserServiceMap.get(head.getKey()).sayHello("are you ok?"));

        }


    }

    public static <K, V> Map.Entry<K, V> getHead(LinkedHashMap<K, V> map) {
        return map.entrySet().iterator().next();
    }



}
